﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AmorCanino.Common;

namespace AmorCanino.Web.Models.Services
{
    public class ArticleService : BaseService, IArticleService
    {
       
        public IEnumerable<Models.Article> GetTopMarked()
        {
            return GetArticles(ConfigurationHandler.MarkedArticles, true);
        }

        public IEnumerable<Models.Article> GetTopNew()
        {
            return GetArticles(ConfigurationHandler.NewArticles, false);
        }

        private IEnumerable<Models.Article> GetArticles(int howMany, bool marked)
        {
            var db = new AmorCaninoDBDataContext();

            return db.Products.Where(p => p.Visible && p.Remarked == marked)
                    .OrderByDescending(p => p.ProductId)
                    .Select(p => new Models.Article()
                    {
                        Price = p.Price,
                        ProductId = p.ProductId,
                        SmallDescription = p.SmallDescription,
                        Picture = p.Picture ?? Guid.Empty,
                        Name = p.Name,
                        CategoryId = p.CategoryId
                    }).ToList();
        }
    }
}